<?php
namespace Admin\Controller;
use Think\Controller;
class GroupController extends CommonController {

	public function _initialize(){
	parent::_initialize();
	$this->model="authGroup";
	$this->key="id";	
	$this->title_index= L('group_index');
	$this->title_details=L('group_details');
	$this->title_add=L('group_add');
	}	
	
	//分配权限
	public function assignAccess(){
		$group=M($this->model);
		$con['id']=I('id');
		$group_list=$group->where($con)->find();
		if(!$group_list)
			$this->error(L("group_not_found"));
		$arr=explode(",",$group_list['rules']);
		$this->assign($group_list);
		
		$oop=M('authRule');
		$list=$oop->select();
		foreach($list as  $key=>$value){
			if(in_array($value['id'],$arr))
				$list[$key]['checked']="checked";
			else
				$list[$key]['checked']="";
		}
		$this->assign("list",$list);
		$this->assign("main_title",L("assign_access"));
		//dump($list);
		$this->display();
	}
	
	public function updateRules(){
		$oop=M($this->model);
		$oop->create();
		$oop->rules=implode(",",I('check_child'));
		if($oop->save())
			$this->success(L("update_success"));
		else
			$this->error(L("update_failed"));	
	}
	
}
?>